Page({
 
  /**
   * 页面的初始数据
   */
  data: {
    openid:''
  },
  open:function(){
    wx.login({
      success:function(res){
        var that = this;
        var header = {
          'content-type':'application/x-www-form-urlencoded',
          'token': wx.getStorageSync('token')//读取cookie 拿到登录之后异步保存的token值
        };
        if (res.code) {
          console.log(res.code);
          wx.request({//getOpenid
            url: 'https://api.weixin.qq.com/sns/jscode2session',
              data: {
                appid: "wxb9e25f5e185538f3", //wxa7a045221af038f0
                secret: '195c8d9e244a91522d74df2509cac863',//74d2d89f369555be8e75f10d4391fda4
                grant_type: 'authorization_code',
                js_code: res.code
              },
           method: 'GET',
          header: header,
            success: function (res) {
              var openid = res.data.openid; //登录之后返回的openid
              // this.setData({
              //   openid: res.data.openid
              // });
              console.log(openid+'我的openid')
              wx.setStorageSync('openid', openid) //储存openid
              if (openid != null & openid != undefined) {
                wx.getUserInfo({
                  success: function (res) {
                   console.log(res);
                  },
                  fail: function (res) {
                    //console.info('用户拒绝授权');
                  }
                }); 
              }else{
                console.info('获取用户openid失败');
              }
            },
            fail: function (res) {
              console.info('获取用户openid失败');
              console.log(error);
            }
          })
        }
      }
    })
  },
  nav2order(){
    wx.navigateTo({
      url: './order/index',
    })
  },
  nav2address(){
    wx.navigateTo({
      url: './address/manage/index',
    })
  },
})